package com.wifi.a007.wifiFragment;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.VideoView;

import com.wifi.a007.R;
import com.wifi.a007.ViewName;

import java.util.ArrayList;
import java.util.List;


public class wifiNet extends Fragment {
    private WifiManager wifi;
    private WifiInfo wifiInfo;
    private wifiAdapter adapter;
    private List<HotInfo> wifiList=new ArrayList<>();


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View view=inflater.inflate(R.layout.wifi_fragment_main_layout,container,false);

         wifi= (WifiManager)getActivity().getSystemService(Context.WIFI_SERVICE);
         wifiInfo=wifi.getConnectionInfo();
        ViewName.initWifiNetFragment(view);
        initWifi();

        setTitle();
        RecyclerView recyclerView=(RecyclerView)view.findViewById(R.id.recycler_view);
        LinearLayoutManager layoutManager=new LinearLayoutManager(getActivity());
      // layoutManager.setOrientation(LinearLayoutManager.ve);水平布局
//什么都不做就是从上到下的布局
        //StaggeredGridLayoutManager layoutManager=new StaggeredGridLayoutManager(3,StaggeredGridLayoutManager.VERTICAL);


        recyclerView.setLayoutManager(layoutManager);
        adapter=new wifiAdapter(wifiList);
        recyclerView.setAdapter(adapter);

        ViewName.adapter=this.adapter;
        ViewName.wifiList=this.wifiList;



        return view;
    }



    private void initWifi(){
        wifiList.add(new HotInfo("good", "bob", "good",3,4));

            List<ScanResult> results = wifi.getScanResults();



            for (ScanResult s : results) {

                wifiList.add(new HotInfo(s));
            }




    }
    public static  void addWifi(){
        ViewName.wifiList.add(new HotInfo("good", "bob", "good",3,4));





    }

    private void setTitle(){

        String  wifiString="BSSID: "+wifiInfo.getBSSID()+"\nMAC: "+wifiInfo.getMacAddress()+"\nIP: "+wifiInfo.getIpAddress();

        ViewName.wifiConnectName.setText(wifiInfo.getSSID());
        ViewName.wifiConnectInfo.setText(wifiString);




    }




}
